//
//  CombineLatestViewController.swift
//  testRxSwift
//
//  Created by 火星人 on 2017/7/25.
//  Copyright © 2017年 火星人. All rights reserved.
//

import UIKit
import RxSwift

class CombineLatestViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addTapWithHandle { (tap) in
            
            let disBag = DisposeBag()
            
            let subjectString = PublishSubject<String>()
            let subjectInt = PublishSubject<Int>()
            
            // 获取两个序列的最新值，并通过某个函数对其进行处理，处理完之后返回一个新的发射值。
            Observable.combineLatest(subjectString, subjectInt){
                    (str, intValue) -> String in
                
                    return "\(str) + \(intValue)"
                }
                .subscribe({ (ev) in
                    print(ev)
                })
                .disposed(by: disBag)
            
            subjectString.onNext("111")
            subjectInt.onNext(7)
            subjectInt.onNext(8)
            subjectInt.onNext(9)
            
            subjectString.onNext("222")
            subjectString.onNext("333")
            subjectString.onNext("444")
            subjectString.onNext("555")
            
            subjectInt.onNext(10)
            subjectInt.onNext(11)
            subjectInt.onNext(12)
        }
    }
}
